package com.taoyibao.hongcanting.ui.home.delegate;

import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.taoyibao.hongcanting.R;
import com.taoyibao.hongcanting.base.delegate.ToolbarDelegate;
import com.taoyibao.hongcanting.cache.SpUtils;
import com.taoyibao.hongcanting.event.EventMusic;
import com.taoyibao.hongcanting.model.BannerModel;
import com.taoyibao.hongcanting.model.DishModel;
import com.taoyibao.hongcanting.ui.home.activity.MenuActivity;
import com.taoyibao.hongcanting.ui.home.activity.ShoppingCartActivity;
import com.taoyibao.hongcanting.ui.home.views.BannerArea;
import com.taoyibao.hongcanting.ui.home.views.FeaturesArea;
import com.taoyibao.hongcanting.ui.home.views.RecommendArea;
import com.taoyibao.hongcanting.ui.login.activity.LoginActivity;
import com.taoyibao.hongcanting.ui.mine.activity.WaitPayActivity;
import com.taoyibao.hongcanting.utils.CodeUtils;

import org.greenrobot.eventbus.EventBus;

import java.util.List;

/**
 * @author TangAnna
 * @description: 首页模块
 * @date :${DATA} 14:51
 */
public class HomeFragmentDelegate extends ToolbarDelegate implements View.OnClickListener, ToolbarDelegate.OnLeftCilckListener {

    private RecommendArea mRecommendArea;
    private FeaturesArea mFeaturesArea;
    private BannerArea mBannerArea;
    /**
     * 就餐中的时候的订单ID
     */
    private String mOrderId;

    @Override
    public int getRootLayoutId() {
        return R.layout.fragment_home;
    }

    @Override
    public void initWidget() {
        super.initWidget();
        setHideTitle();
        setLeftImg(R.drawable.position);
        setLeftText(CodeUtils.getIdString(R.string.string_restaurantName));
        setRightOnlyImg(R.drawable.saomiao);
        setHideDivder();
        setOnLeftCilckListener(this);
        mRecommendArea = get(R.id.recommendArea);
        mFeaturesArea = get(R.id.featuresArea);
        mBannerArea = get(R.id.banner_home);
        get(R.id.layout_home_showCart).setOnClickListener(this);
        get(R.id.btn_home_menu).setOnClickListener(this);
        get(R.id.iv_home_music).setOnClickListener(this);

    }

    /**
     * 设置镇店之宝的数据
     */
    public void setRecommendAreaData(List<DishModel> data) {
        mRecommendArea.setData(data);
    }

    /**
     * 设置推荐菜品的数据
     */
    public void setFeaturesAreaData(List<DishModel> data) {
        mFeaturesArea.setData(data);
    }

    /**
     * 设置banner数据
     *
     * @param data
     */
    public void setBannerData(List<BannerModel> data) {
        mBannerArea.setData(data);
    }

    @Override
    public void onClick(View v) {
        if (v.getId() == R.id.iv_home_music) {
            EventBus.getDefault().post(new EventMusic(false, false));
            return;
        }
        if (SpUtils.getLoginStatus()) {
            switch (v.getId()) {
                case R.id.layout_home_showCart://查看购物车
                    ShoppingCartActivity.open(getActivity(), "HomeFragmentDelegate");
                    break;

                case R.id.btn_home_menu://点餐
                    if (!TextUtils.isEmpty(mOrderId)) {
                        //就餐中 跳转到待支付订单页面
                        WaitPayActivity.open(getActivity(), mOrderId);
                    } else {
                        MenuActivity.open(getActivity());
                    }
                    break;
            }
        } else {
            LoginActivity.open(getActivity(), "");
        }

    }

    /**
     * 设置就餐状态
     *
     * @param isEating true 就餐中  false 未就餐
     * @param disk     就餐中 显示的桌号  未就坐时传""
     */
    public void setEatStatus(boolean isEating, String disk, String orderId) {
        mOrderId = orderId;
        if (isEating) {//就餐中
            ((TextView) get(R.id.btn_home_menu)).setText(CodeUtils.getIdString(R.string.string_jiuCanZhong));
            ((TextView) get(R.id.tv_home_status)).setText("您为" + disk + "号桌");
        } else {
            ((TextView) get(R.id.btn_home_menu)).setText(CodeUtils.getIdString(R.string.string_diancan));
            ((TextView) get(R.id.tv_home_status)).setText(CodeUtils.getIdString(R.string.string_ninShangWeiJiuZuo));

        }
    }

    @Override
    public void onLeftClick(View view) {

    }
}
